const ExcelJS = require('exceljs');

// Load an existing workbook
const workbook = new ExcelJS.Workbook();

workbook.xlsx.readFile('sample.xlsx')
    .then(() => {
        // File loaded successfully
        // Now you can work with the workbook and its worksheets

        // Get the first worksheet
        const worksheet = workbook.getWorksheet(1);

        // Define the array of data to be inserted
        const newData = [
            [null, 'New Value 1', 'New Value 2', 'New Value 3', 'New Value 4', 'New Value 5', 'New Value 6', 'New Value 7', 'New Value 8', 'New Value 9', 'NEW VALUE 10'],
            [null, 'New Value 4', 'New Value 5', 'New Value 6', 'New Value 7', 'New Value 8', 'New Value 9', 'New Value 10', 'New Value 11', 'New Value 12', 'NEW VALUE 13']
        ];

        // Define the starting row and column
        const startRow = 10;
        const startColumn = 2; // Column B

        // Insert the new data between rows 9 and 10, starting from column B
        worksheet.spliceRows(startRow, 0, ...newData);

        // Save the workbook with the inserted data
        return workbook.xlsx.writeFile('modified_file.xlsx');
    })
    .then(() => {
        console.log('New data inserted successfully!');
    })
    .catch(err => {
        // Handle errors
        console.error('Error:', err);
    });